/*--------------------------------------------------------------
 * File: demo42.c 编码类型：C语言  UTF-8
 * Author WRS (1352509846@qq.com)
 * 功能: 计算数组元素平均值
 * Version 0.1
 * Date 2022-03-28 
 * 
 * @copyright Copyright (c) 2022
 * 
----------------------------------------------------------------*/
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int n,i;
    float num[100] = {0};
    float sum = 0;
    float avg = 0;
    printf("输入元素个数：");
    scanf("%d",&n);

    while(n>100 || n <= 0)
    {
        printf("Error 数字需要在1到100之间\n");
        printf("再次输入：");
        scanf("%d",&n);
    }

    for(i=0; i<n; i++)
    {
        printf("%d 输入数字： ",i+1);
        scanf("%f",&num[i]);
        sum += num[i];
    }

    avg = (float)sum / n;

    printf("平均值 %.2f\n",avg);

    return 0;
}
